package de.stefanocke.roo.xtend

import org.springframework.roo.model.ImportRegistrationResolver
import org.springframework.roo.model.JavaType

import static extension de.stefanocke.roo.xtend.RooExtensions.*

class ImportResolverExtensions{
	ImportRegistrationResolver importRegistrationResolver
	
	def init(ImportRegistrationResolver importRegistrationResolver) {
		this.importRegistrationResolver = importRegistrationResolver
		this
	}	
	def resolve(JavaType javaType){ 
		javaType.getNameIncludingTypeParameters(false, importRegistrationResolver)
	}
	def resolveStatic(JavaType javaType){ 
		javaType.getNameIncludingTypeParameters(true, importRegistrationResolver)
	}
	def resolve(String fqn){ 
		fqn.javaType.resolve
	}

	def resolveStatic(String fqn){ 
		fqn.javaType.resolveStatic
	}
	
	//import is similar to resolve, but it erases all type argument information
	//and only considers the raw type. 
	
	def import_(Class<?> clazz){ 
		clazz.javaType.fqn.import_
	}
	def import_(JavaType javaType){ 
		javaType.fqn.import_
	}
	def import_(String fqn){
		fqn.javaType.resolveStatic
	}
	
	def importRegistrationResolver(){
		importRegistrationResolver
	}
	
}